package day240816;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortPointDemo {
    public static void main(String[] args) {

        List<Point> list = new ArrayList<>();
        list.add(new Point(1,2));
        list.add(new Point(2,3));
        list.add(new Point(7,2));
        list.add(new Point(12,2));
        list.add(new Point(8,5));
        System.out.println(list);
        Collections.sort(list, (p1,p2)->{
            int len1=p1.getX()*p1.getX()+ p1.getY()*p1.getY();
            int len2=p2.getX()*p2.getX()+ p2.getY()*p2.getY();
            return len1-len2;
        });
        System.out.println("按照到原点距离升序："+list);//降序len2-len1
    }
}
